<?php

namespace app\api\service;

use app\admin\model\PoliteArticle;
use app\admin\model\PoliteComprehensive;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Exception;

class Home
{
    public static function getNewsList($pageNum,$pageSize): array
    {
        $map=[];
        $map[]=['type','=',10];
        $model=new PoliteArticle();
        $list=$model->where($map)->order('order asc')->field('id,create_time,title,cover_photo')->page($pageNum,$pageSize)->select();
        return $list->isEmpty()?[]:$list->toArray();
    }

    public static function getRecommendList(){
        $model=new PoliteComprehensive();
        $map=[
            ['is_recommend','=',1],
        ];
        $list=$model->where($map)->order('order asc,score desc')->field('id,name,type,category,addr_name,files,score')->page(1,10)->select();
        $list=$list->isEmpty()?[]:$list->toArray();
        foreach ($list as $k=>$v){
            $configLib=Comprehensive::getConfigLib($v['category']);
            $list[$k]=Comprehensive::resetRow($v,$configLib);
        }
        return $list;
    }

}